/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spring;

import engine.Singleton;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import server.ServeOneThread;

/**
 *
 * @author Alexx
 */
public class MultiServer extends Thread implements IServer
{
    static final int PORT = 8888;
    @Override
    public void run()
    {
        ServerSocket s = null;
        try {
            s = new ServerSocket(PORT);
        } catch (IOException ex) {
            Logger.getLogger(MultiServer.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Server Started");
        Singleton.getInstance();
        try
        {
            while (true)
            {
                Socket socket = null;
                try {
                    socket = s.accept();
                } catch (IOException ex) {
                    Logger.getLogger(MultiServer.class.getName()).log(Level.SEVERE, null, ex);
                }
                try
                {
                    ServeOneThread clients = new ServeOneThread(socket);
                    
                }
                catch (IOException e)
                {
                    try {
                        socket.close();
                    } catch (IOException ex) {
                        Logger.getLogger(MultiServer.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
        finally
        {
            try {
                s.close();
            } catch (IOException ex) {
                Logger.getLogger(MultiServer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
